package love.lkzy.oj.codeSandBox.config;


import cn.hutool.core.io.FileUtil;
import love.lkzy.oj.codeSandBox.ICodeSandBox;
import love.lkzy.oj.codeSandBox.impl.ExampleCodeBoxSandBoxImpl;
import love.lkzy.oj.codeSandBox.model.SandBoxConfigParams;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.io.File;


@Configuration
public class SandBoxConfig {

    @Resource
    private SandBoxConfigParams params;

    @Bean
    public ICodeSandBox sandBoxConfiguration() {
        System.out.println("沙箱初始化...");

        // 如果根目录下没有代码文件夹tempCodeDir则创建
        String userDir = System.getProperty("user.dir");
        String codeDirPath = userDir + File.separator + "tempCodeDir";
        if(!FileUtil.exist(codeDirPath)){
            FileUtil.mkdir(codeDirPath);
        }

        System.out.println("-----" + System.getProperty("user.dir"));

        //if (params.getType().equals("example")) return new ExampleCodeBoxSandBoxImpl();
        //if (params.getType().equals("remote")) return new RemoteCodeBoxSandBoxImpl();
        ExampleCodeBoxSandBoxImpl res = new ExampleCodeBoxSandBoxImpl();

        return res;
    }

}
